// 没用

// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {HouseList} from '../domains/houselist.domain';
import {House} from '../domains/house.domain';

/**
 *
 */
@Injectable({
  providedIn: 'root'
})
export class HouseServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'houseServiceSvr.assx/';
  }


  saveHouse(token: string, detailAddress: string, size: number, rent: number, type: number, rooms: number, province: string, city: string, region: string, description: string, community: string, parentId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('detailAddress', detailAddress.toString())
      .append('size', size.toString())
      .append('rent', rent.toString())
      .append('type', type.toString())
      .append('rooms', rooms.toString())
      .append('province', province.toString())
      .append('city', city.toString())
      .append('region', region.toString())
      .append('description', description.toString())
      .append('community', community.toString())
      .append('parentId', parentId.toString());
    return this.request.post<number>(this.baseUrl + 'saveHouse', httpParams).then((res) => {
      return res;
    });
  }


  listHouse(token: string, province: string, city: string, region: string, minSize: number, maxSize: number, minRent: number, maxRent: number, order: number, type: number, skip: number, size: number): Promise<HouseList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('province', province.toString())
      .append('city', city.toString())
      .append('region', region.toString())
      .append('minSize', minSize.toString())
      .append('maxSize', maxSize.toString())
      .append('minRent', minRent.toString())
      .append('maxRent', maxRent.toString())
      .append('order', order.toString())
      .append('type', type.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<HouseList>(this.baseUrl + 'listHouse', httpParams).then((res) => {
      return new HouseList(res);
    });
  }


  batchUpdateEnable(token: string, houseIds: string, enable: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseIds', houseIds.toString())
      .append('enable', enable.toString());
    return this.request.post<number>(this.baseUrl + 'batchUpdateEnable', httpParams).then((res) => {
      return res;
    });
  }


  updateStatus(token: string, houseId: string, status: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString())
      .append('status', status.toString());
    return this.request.post<number>(this.baseUrl + 'updateStatus', httpParams).then((res) => {
      return res;
    });
  }


  listHouseBackend(token: string, province: string, city: string, region: string, detailAddress: string, type: number, status: number, enable: number, skip: number, size: number): Promise<HouseList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('province', province.toString())
      .append('city', city.toString())
      .append('region', region.toString())
      .append('detailAddress', detailAddress.toString())
      .append('type', type.toString())
      .append('status', status.toString())
      .append('enable', enable.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<HouseList>(this.baseUrl + 'listHouseBackend', httpParams).then((res) => {
      return new HouseList(res);
    });
  }


  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }


  getHouseByPrimaryKey(token: string, houseId: string, flag: boolean): Promise<House> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString())
      .append('flag', flag.toString());
    return this.request.post<House>(this.baseUrl + 'getHouseByPrimaryKey', httpParams).then((res) => {
      return new House(res);
    });
  }


  updateEnable(token: string, houseId: string, enable: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString())
      .append('enable', enable.toString());
    return this.request.post<number>(this.baseUrl + 'updateEnable', httpParams).then((res) => {
      return res;
    });
  }


  deleteHouse(token: string, houseId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString());
    return this.request.post<number>(this.baseUrl + 'deleteHouse', httpParams).then((res) => {
      return res;
    });
  }


  updateHouse(token: string, id: string, detailAddress: string, size: number, rent: number, province: string, city: string, region: string, description: string, community: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString())
      .append('detailAddress', detailAddress.toString())
      .append('size', size.toString())
      .append('rent', rent.toString())
      .append('province', province.toString())
      .append('city', city.toString())
      .append('region', region.toString())
      .append('description', description.toString())
      .append('community', community.toString());
    return this.request.post<number>(this.baseUrl + 'updateHouse', httpParams).then((res) => {
      return res;
    });
  }
}
